package com.hemaapp.yjnh.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.uu.utils.uuUtils;
import com.google.gson.Gson;

import xtom.frame.XtomObject;
import xtom.frame.exception.DataParseException;

/**帖子详情,0唠嗑帖子 1田家农货 2有机 3地标特产 4走走 5田家日志
 * @author ZhangGuiyou
 * Date: 2015-8-6 16:05
 */
public class Blog extends XtomObject implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private String id;// 主键id	
	private String client_id;// 发布人主键id	用于点击作者头像进入作者主页
	private String nickname;// 发布人昵称	
	private String avatar;// 发布人头像	
	private String address;// 发布人地址	
	private String mobile;// 发布人联系方式	
	private String qq;// 发布人QQ	
	private String farmer_starscore;// 发布人口碑星数	
	private String farmer_replycount;// 发布人口碑数	
	private String type;// blog类别	
	//0唠嗑帖子；1田家农货；2有机；3地标；4村游；5田家日志；6特产；9乐乐；11粮库；
	//71走走房车露营；72走走自驾车露营；73走走帐篷露营；74走走商品区；75走走房车；
	//81苗木；82花卉；83家电；84日用品；10众农
	private String name;// 名称	
	private String typename;// 所属类别	
	private String sn;// 产品编号	
	private String weight;// 重量	
	private String unit;// 规格单位	默认‘斤’
	private String ALevel;// A级别	0：否；1：A级绿色；2：AA级绿色
	private String organicflag;//有机食物标签	0不是 1 是
	private String islamflag;//清真标签	0否 1是
	private String leftcount;// 库存	
	private String topkeytype;// 全部置顶标记	0：否1：是
	private String saleflag;// 上架状态	0：否 1：是
	private String topflag;//置顶状态	0：否 1：是
	private String cheapflag;// 热销抢购	0：否；1：是
	private String returnflag;// 允许退货标记	0不允许 1允许
	private String distance;// 距离	
	private String price;// 现价
	private String oldprice;// 原价	
	private String score;// 粮票价	1
	private String score_percent;// 粮票占比	1-10代表10%-100%
	private String expressfee;// 运费（每斤）	
	private String district_name;// 地区/民族	
	private String replycount;// 回复数	
	private String goodcount;// 好评数
	private String sellcount;// 已卖数
	private String collectflag;// 收藏标记	0未收藏；1收藏
	private String collectcount;// 收藏数	
	private String starscore;// 星级	
	private String goodflag;// 点赞标记	0无 1有
	private String content;// 帖子详情	
	private String buycontent;// 购买须知	
	private String imgurlbig;// 大图地址	当videourl不为空时，此字段存储的是视频首帧图片
	private String imgurl;// 缩略图地址	当videourl不为空时，此字段存储的是视频首帧图片
	private String imgcount;// 图片总计数	一个整数
	private String regdate;// 帖子发布时间
	private String one_spec;
	private String two_spec;
	
	private String attributeItems;//商品属性列表	子列表

	private boolean isCheck;//删除收藏和购物车中选择商品时使用
	
	private ArrayList<ImageItem> items = new ArrayList<>();//唠嗑中的图片
	private ArrayList<AttributeItems> attributes= new ArrayList<AttributeItems>();
	private List<ImgItemsBean> imgItems = new ArrayList<>();//轮播图片
	private List<ImgItemsBean> img2Items = new ArrayList<>();//详情图片
	
	public Blog(JSONObject jsonObject) throws DataParseException {
		if (jsonObject != null) {
			try {
				id = get(jsonObject, "id");
				client_id = get(jsonObject, "client_id");
				nickname = get(jsonObject, "nickname");
				avatar = get(jsonObject, "avatar");
				address = get(jsonObject, "address");
				mobile = get(jsonObject, "mobile");
				qq = get(jsonObject, "qq");
				farmer_starscore = get(jsonObject, "farmer_starscore");
				farmer_replycount = get(jsonObject, "farmer_replycount");
				type = get(jsonObject, "type");
				name = get(jsonObject, "name");
				typename = get(jsonObject, "typename");
				unit = get(jsonObject, "unit");
				cheapflag = get(jsonObject, "cheapflag");
				distance = get(jsonObject, "distance");
				score = uuUtils.formatAfterDot2(get(jsonObject, "score"));
				score_percent = get(jsonObject, "score_percent");
				sn = get(jsonObject, "sn");
				weight = get(jsonObject, "weight");
				ALevel = get(jsonObject, "ALevel");
				organicflag = get(jsonObject, "organicflag");
				islamflag = get(jsonObject, "islamflag");
				leftcount = get(jsonObject, "leftcount");
				topkeytype = get(jsonObject, "topkeytype");
				saleflag = get(jsonObject, "saleflag");
				topflag = get(jsonObject, "topflag");
				returnflag = get(jsonObject, "returnflag");
				price = uuUtils.formatAfterDot2(get(jsonObject, "price"));
				oldprice = uuUtils.formatAfterDot2(get(jsonObject, "oldprice"));
				expressfee = uuUtils.formatAfterDot2(get(jsonObject, "expressfee"));
				district_name = get(jsonObject, "district_name");
				replycount = get(jsonObject, "replycount");
				goodcount = get(jsonObject, "goodcount");
				sellcount = get(jsonObject, "sellcount");
				collectflag = get(jsonObject, "collectflag");
				collectcount = get(jsonObject, "collectcount");
				starscore = get(jsonObject, "starscore");
				goodflag = get(jsonObject, "goodflag");
				content = get(jsonObject, "content");
				buycontent = get(jsonObject, "buycontent");
				imgurlbig = get(jsonObject, "imgurlbig");
				imgurl = get(jsonObject, "imgurl");
				imgcount = get(jsonObject, "imgcount");
				regdate = get(jsonObject, "regdate");
				attributeItems = get(jsonObject, "attributeItems");
				one_spec = get(jsonObject, "one_spec");
				two_spec = get(jsonObject, "two_spec");
				String images1 = get(jsonObject, "imgItems");//轮播图
				String images2 = get(jsonObject, "img2Items");//详情图片

				if (null != attributeItems && !attributeItems.isEmpty()) {
					JSONArray jsons = new JSONArray(attributeItems);
					for (int i = 0; i < jsons.length(); i++) {
	                    JSONObject child = jsons.getJSONObject(i);
	                    AttributeItems attr = new AttributeItems(child);
	                    attributes.add(attr);
	                }
				}
				
				if (!isNull(images1)) {
					JSONArray jsons = new JSONArray(images1);
					for (int i = 0; i < jsons.length(); i++) {
	                    JSONObject child = jsons.getJSONObject(i);
	                    ImageItem item = new ImageItem(child);
	                    items.add(item);
                        imgItems.add(new Gson().fromJson(child.toString(), ImgItemsBean.class));
	                }
				}

                if (!isNull(images2)) {
                    JSONArray jsons = new JSONArray(images2);
                    for (int i = 0; i < jsons.length(); i++) {
                        JSONObject child = jsons.getJSONObject(i);
                        img2Items.add(new Gson().fromJson(child.toString(), ImgItemsBean.class));
                    }
                }

				log_i(toString());
			} catch (JSONException e) {
				throw new DataParseException(e);
			}
		}
	}

    public String getOne_spec() {
        return one_spec;
    }

    public String getTwo_spec() {
        return two_spec;
    }

    public String getId() {
		return id;
	}

	public String getClient_id() {
		return client_id;
	}

	public String getNickname() {
		return nickname;
	}

	public String getAvatar() {
		return avatar;
	}

	public String getAddress() {
		return address;
	}

	public String getMobile() {
		return mobile;
	}

	public String getQq() {
		return qq;
	}

	public String getFarmer_starscore() {
		return farmer_starscore;
	}

	public String getFarmer_replycount() {
		return farmer_replycount;
	}

	public String getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public String getTypename() {
		return typename;
	}

	public String getSn() {
		return sn;
	}

	public String getWeight() {
		return weight;
	}

	public String getUnit() {
		return unit;
	}

	public String getALevel() {
		return ALevel;
	}

	public String getOrganicflag() {
		return organicflag;
	}

	public String getIslamflag() {
		return islamflag;
	}

	public String getLeftcount() {
		return leftcount;
	}

	public String getTopkeytype() {
		return topkeytype;
	}

	public String getSaleflag() {
		return saleflag;
	}

	public String getTopflag() {
		return topflag;
	}

	public String getCheapflag() {
		return cheapflag;
	}

	public String getReturnflag() {
		return returnflag;
	}

	public String getDistance() {
		return distance;
	}

	public String getPrice() {
		return price;
	}

	public String getOldprice() {
		return oldprice;
	}

	public String getScore() {
		return score;
	}

	public String getScore_percent() {
		return score_percent;
	}

	public String getExpressfee() {
		return expressfee;
	}

	public String getDistrict_name() {
		return district_name;
	}

	public String getReplycount() {
		return replycount;
	}

	public String getGoodcount() {
		return goodcount;
	}

	public String getSellcount() {
		return sellcount;
	}

	public String getCollectflag() {
		return collectflag;
	}

	public String getCollectcount() {
		return collectcount;
	}

	public String getStarscore() {
		return starscore;
	}

	public String getGoodflag() {
		return goodflag;
	}

	public String getContent() {
		return content;
	}

	public String getBuycontent() {
		return buycontent;
	}

	public String getImgurlbig() {
		return imgurlbig;
	}

	public String getImgurl() {
		return imgurl;
	}

	public String getImgcount() {
		return imgcount;
	}

	public String getRegdate() {
		return regdate;
	}

	public boolean isCheck() {
		return isCheck;
	}

	public void setGoodflag(String goodflag) {
		this.goodflag = goodflag;
	}

	public void setCollectflag(String collectflag) {
		this.collectflag = collectflag;
	}

	public void setReplycount(String replycount) {
		this.replycount = replycount;
	}

	public void setGoodcount(String goodcount) {
		this.goodcount = goodcount;
	}

	public void setCheck(boolean isCheck) {
		this.isCheck = isCheck;
	}

	public ArrayList<AttributeItems> getAttributeItems() {
		return attributes;
	}
	
	public ArrayList<ImageItem> getItems() {
		return items;
	}

	public List<ImgItemsBean> getImgItems() {
		return imgItems;
	}

	public List<ImgItemsBean> getImg2Items() {
		return img2Items;
	}
}
